/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package busy.tomcat;

import java.io.IOException;
import java.io.Writer;
import java.util.Map;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**I
 *
 * @author martin
 */
public class testServlet extends HttpServlet{
  
  String form = "<form name=\"input\" action=\"http://localhost:8080/\" method=\"post\">\n" +
                "Username: <input type=\"text\" name=\"user\">\n" +
                "<input type=\"submit\" value=\"Submit\">" +
                "<input type=\"checkbox\" name=\"vehicle\" value=\"Bike\">I have a bike<br>\n" +
                "<input type=\"checkbox\" name=\"vehicle\" value=\"Car\">I have a car"+
                "<input type=\"radio\" name=\"sex\" value=\"male\">Male<br>\n" +
                "<input type=\"radio\" name=\"sex\" value=\"female\">Female" +
                "First name: <input type=\"text\" name=\"firstname\"><br>\n" +
                "Last name: <input type=\"text\" name=\"lastname\">\n" +
                "Password: <input type=\"password\" name=\"pwd\">" +
                "</form>";
  
  
  @Override
  public void service(final HttpServletRequest req, final HttpServletResponse resp) throws IOException{
    Map<String,String[]> request = req.getParameterMap();
    Writer w = resp.getWriter();
    
    w.write("<html><body>Hello, World!<br />");
    w.write(form);
    for (Map.Entry<String,String[]> param : request.entrySet()){
      w.write(param.getKey() + " : ");
      for (String val : param.getValue()){
        w.write(val+", ");
      }
      w.write(";<br />");
    }
    w.write("</body></html>");
    
    w.flush();
  }

}
